package com.leet.code.lcof;

import com.algorithm.model.ListNode;

public class Code18 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode head3 = new ListNode(3);
        ListNode head2 = new ListNode(2);
        head.next = head3;
        head3.next = head2;

        new Code18().deleteNode(head, 3);

        while (head != null) {
            System.out.println(head.val);
            head = head.next;
        }
    }

    public ListNode deleteNode(ListNode head, int val) {
        if (head.val == val) {
            return head.next;
        }
        ListNode h = head;

        while (h.next != null) {
            if (val == h.next.val) {
                h.next = h.next.next;
                break;
            }
            h = h.next;
        }

        return head;
    }



}
